/**
 * 高管持股管理初始化
 */
var Djg = {
    id: "DjgTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Djg.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        	{title: '代码', field: 'gDm', visible: true, align: 'center', valign: 'middle'},
            {title: '股票', field: 'gCodeName', visible: true, align: 'center', valign: 'middle'},
            {title: '姓名', field: 'gName', visible: true, align: 'center', valign: 'middle'},
            {title: '代码', field: 'gDm', visible: true, align: 'center', valign: 'middle'},
            {title: '变动日期', field: 'gDate', visible: true, align: 'center', valign: 'middle'},
            {title: '变动股数', field: 'gBdgs', visible: true, align: 'center', valign: 'middle'},
            {title: '成交均价', field: 'gAvgPrice', visible: true, align: 'center', valign: 'middle'},
            {title: '变动后股数', field: 'gBdhgs', visible: true, align: 'center', valign: 'middle'},
            {title: '与董监高关系', field: 'gDjggx', visible: true, align: 'center', valign: 'middle'},
            {title: '变动原因', field: 'gBdtype', visible: true, align: 'center', valign: 'middle'},
            {title: '变动金额', field: 'gBdmoney', visible: true, align: 'center', valign: 'middle'},
            {title: '职位', field: 'gJob', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Djg.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Djg.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加高管持股
 */
Djg.openDetailDjg = function () {
	if (this.check()) {
		var index = layer.open({
		    type: 2,
		    title: '董监高增持明细',
		    area: ['1024px', '600px'], //宽高
		    fix: false, //不固定
		    maxmin: true,
		    content: Feng.ctxPath + '/djg/djg_detail/' + this.seItem.gDm
		});
		this.layerIndex = index;
	}
};

/**
 * 删除高管持股
 */
Djg.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/djg/delete", function (data) {
            Feng.success("删除成功!");
            Djg.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("djgId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询高管持股列表
 */
Djg.search = function () {
    var queryData = {};
    queryData['gDm'] = $("#gDm").val();
    queryData['gBdtype'] = $("#gBdtype").val();
    queryData['zjc'] = $("#zjc").val();
    Djg.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Djg.initColumn();
    var table = new BSTable(Djg.id, "/djg/list", defaultColunms);
    table.setPaginationType("server");
    Djg.table = table.init();
});
